/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.SexType;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class SexTypeDAO extends AbstractDAO implements IDAO<SexType, Integer> {

    @Override
    public List<SexType> getAll() throws Exception {
       String sql = "select * from sex order by "+ SexType.field_sexname +" ASC";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        List<Map<String,Object>> result = this.getCon().queryList(sql);
        List<SexType> ss = new ArrayList<>();
        for (Map<String, Object> map : result) {
            SexType s = new SexType();
            s.setSexID(Integer.parseInt(map.get(SexType.field_sexid).toString()));
            s.setSexName(map.get(SexType.field_sexname).toString());
            ss.add(s);
        }
        return ss;
    }

    @Override
    public int updateSingle(SexType t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(SexType t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(SexType t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public SexType getById(Integer id) throws Exception {
       String sql = "select * from sex where "+ SexType.field_sexid +" = ?";
        System.out.println(sql);
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
            Map<String,Object> map = this.getCon().querySingle(sql,id);
        
            SexType s = new SexType();
            s.setSexID(Integer.parseInt(map.get(SexType.field_sexid).toString()));
            s.setSexName(map.get(SexType.field_sexname).toString());
            
        
        return s;
    }
    
}
